package com.wnhz.work.yz.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.wnhz.work.yz.R;
import com.wnhz.work.yz.bean.ReceptionMessageBean;

import java.util.List;

/**
 * Created by admin on 2016/12/19.
 */
public class ReceptionMessageAdapter extends BaseAdapter {
    private Context context;
    private View.OnClickListener listener;
    private List<ReceptionMessageBean.InfoEntity> mList;

    public ReceptionMessageAdapter(Context context, View.OnClickListener listener, List<ReceptionMessageBean.InfoEntity> mList) {
        this.context = context;
        this.listener = listener;
        this.mList = mList;
    }

    @Override
    public int getCount() {
        return mList.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ReceptionMessageViewHolder viewHolder = new ReceptionMessageViewHolder();
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.reception_item, null);
            viewHolder.tv_name = (TextView) convertView.findViewById(R.id.tv_name);
            viewHolder.tv_type = (TextView) convertView.findViewById(R.id.tv_type);
            viewHolder.tv_company = (TextView) convertView.findViewById(R.id.tv_company);
            viewHolder.tv_grade = (TextView) convertView.findViewById(R.id.tv_grade);
            viewHolder.tv_people = (TextView) convertView.findViewById(R.id.tv_people);
            viewHolder.tv_start_time = (TextView) convertView.findViewById(R.id.tv_start_time);
            viewHolder.tv_end_time = (TextView) convertView.findViewById(R.id.tv_end_time);
            viewHolder.tv_arrange = (TextView) convertView.findViewById(R.id.tv_arrange);
            viewHolder.tv_pass = (TextView) convertView.findViewById(R.id.tv_pass);
            viewHolder.tv_look = (TextView) convertView.findViewById(R.id.tv_look);
            viewHolder.tv_feedback = (TextView) convertView.findViewById(R.id.tv_feedback);

            viewHolder.rl_button = (RelativeLayout) convertView.findViewById(R.id.rl_button);
            viewHolder.rl_feedback = (RelativeLayout) convertView.findViewById(R.id.rl_feedback);
            viewHolder.rl_look = (RelativeLayout) convertView.findViewById(R.id.rl_look);

            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ReceptionMessageViewHolder) convertView.getTag();
        }
        viewHolder.tv_arrange.setOnClickListener(listener);
        viewHolder.tv_arrange.setTag(position);
        viewHolder.tv_pass.setOnClickListener(listener);
        viewHolder.tv_pass.setTag(position);
        viewHolder.tv_feedback.setOnClickListener(listener);
        viewHolder.tv_feedback.setTag(position);
        viewHolder.tv_look.setTag(position);
        viewHolder.tv_look.setOnClickListener(listener);
        //
        viewHolder.tv_name.setText(mList.get(position).getProject_name());
        viewHolder.tv_company.setText("来访公司：" + mList.get(position).getVisit_company());
        viewHolder.tv_grade.setText(mList.get(position).getCustomer_class());
        viewHolder.tv_people.setText("来访人数：" + mList.get(position).getCustom_num() + "人");
        viewHolder.tv_start_time.setText(mList.get(position).getStarttime());
        viewHolder.tv_end_time.setText(mList.get(position).getEndtime());
        //
        String type = mList.get(position).getStatus();
        if ("0".equals(type)) {
//            viewHolder.tv_type.setText("待审核");
            viewHolder.rl_button.setVisibility(View.VISIBLE);
            viewHolder.rl_feedback.setVisibility(View.GONE);
            viewHolder.rl_look.setVisibility(View.GONE);
        } else if ("1".equals(type)) {
//            viewHolder.tv_type.setText("审核过");
            viewHolder.tv_type.setTextColor(0xff008c99);
            viewHolder.rl_button.setVisibility(View.GONE);
            viewHolder.rl_feedback.setVisibility(View.VISIBLE);
            viewHolder.rl_look.setVisibility(View.GONE);
        } else if ("2".equals(type)) {
//            viewHolder.tv_type.setText("不通过");
            viewHolder.tv_type.setTextColor(0xffff0000);
            viewHolder.rl_button.setVisibility(View.GONE);
            viewHolder.rl_feedback.setVisibility(View.GONE);
            viewHolder.rl_look.setVisibility(View.GONE);
        } else if ("3".equals(type)) {
//            viewHolder.tv_type.setText("进行中");
            viewHolder.tv_type.setTextColor(0xff008c99);
            viewHolder.tv_type.setTextColor(0xff008c99);
            viewHolder.rl_button.setVisibility(View.GONE);
            viewHolder.rl_feedback.setVisibility(View.GONE);
            viewHolder.rl_look.setVisibility(View.VISIBLE);
        } else if ("4".equals(type)) {
            viewHolder.rl_look.setVisibility(View.GONE);
            viewHolder.rl_button.setVisibility(View.GONE);
            viewHolder.rl_feedback.setVisibility(View.VISIBLE);
//            "4" 结束 待反馈
        } else {
            viewHolder.rl_look.setVisibility(View.GONE);
            viewHolder.rl_button.setVisibility(View.GONE);
            viewHolder.rl_feedback.setVisibility(View.GONE);
//“5”已反馈
        }
        viewHolder.tv_type.setText("" + mList.get(position).getStatus_name());

        return convertView;
    }

    class ReceptionMessageViewHolder {
        TextView tv_name;
        TextView tv_type;
        TextView tv_company;
        TextView tv_grade;
        TextView tv_people;
        TextView tv_start_time;
        TextView tv_end_time;
        TextView tv_arrange;
        TextView tv_pass;
        TextView tv_feedback;
        TextView tv_look;

        RelativeLayout rl_button;
        RelativeLayout rl_feedback;
        RelativeLayout rl_look;
    }
}
